#include "windows_utils.h"

void BlitBuffer(const void* data, int width, int height, HWND window)
{
	PAINTSTRUCT ps;
	BeginPaint(window, &ps);
	HDC dc = GetDC(window);
	
	BITMAPINFO bi;
	memset(&bi, 0, sizeof(bi));
	bi.bmiHeader.biSize = sizeof(bi);
	bi.bmiHeader.biWidth = width;
	bi.bmiHeader.biHeight = height;
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 32;
	bi.bmiHeader.biCompression = BI_RGB;

	StretchDIBits( dc, 0, 0, width, height, 0, 0, width, height, data, &bi, DIB_RGB_COLORS, SRCCOPY );

	ReleaseDC(window, dc);
	EndPaint(window, &ps);
}

void RegisterClass(const wchar_t* className, HINSTANCE hInstance, WNDPROC wndProc)
{
	WNDCLASSEX wcex;

	wcex.cbSize			= sizeof(WNDCLASSEX); 
	wcex.style			= CS_DBLCLKS;
	wcex.lpfnWndProc	= wndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= NULL;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= className;
	wcex.hIconSm		= NULL;

	RegisterClassEx(&wcex);
}